using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BlogSystem.Ability.Docking.ReplyApp;
using BlogSystem.Ability.Docking.ReplyApp.Dto;
using BlogSystem.Ability.Docking.UserApp.Dto;
using BlogSystem.Web.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;

namespace BlogSystem.Web.Controllers
{
    public class ReplyController : BaseController
    {
        public IReplyServicer ReplyServicer { get; set; }

        [HttpPost("{token}")]
        public async Task<bool> AddReplyAsync(string token, ReplyCreateDto createDto)
        {
            #region 需要剔除写在AOP中，Token与此业务逻辑无关联
            // var dic = (Dictionary<string, LoginSuccessDto>)Cache.Get("token");
            if (LoginSuccessInfo != null)
            {
                createDto.UserId = LoginSuccessInfo.Id;
                createDto.NickName = LoginSuccessInfo.Username;
                #endregion
                return await ReplyServicer.AddReplyDto(createDto);
            }
            return false;
        }

        [HttpGet]
        public async Task<List<ReplyDto>> GetReplyAsync(int newsId)
        {
          return await  ReplyServicer.GetReplyAsync(newsId);
        }
    }
}